//
//  LoansRootNewsViewController.swift
//  KaMengApplication
//
//  Created by DUONIU_MAC on 2018/10/22.
//  Copyright © 2018年 DUONIU_MAC. All rights reserved.
//

import UIKit
import XLPagerTabStrip

@objc protocol LoansRootNewsDelegate {
    @objc optional func changeScrollHeight(height:CGFloat) //改变滑动高度
    @objc optional func updateTitle() //刷新标题
}

class LoansRootNewsViewController: InformationPageViewController {

    weak var loansDelegate : LoansRootNewsDelegate?
    
    override func viewDidLoad() {
        super.viewDidLoad()

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    //MARK: 更多标签
    override func moreLabel() {
        
        let dataArray = [todayHeadlines,unsecuredLoans,mortgageLoan,consumerLoans,businessLoan,providentFundLoan,smallLoans,mortgageStrategy,carLoanStrategy,hotReading,newGash]
        
        let moreLabelVC = MoreLabelViewController.init(dataArray: dataArray)
        moreLabelVC.labelBlock = {(index) in
            self.moveToViewController(at: index.row, animated: true) //切换至选择标签
        }
        self.present(moreLabelVC, animated: false, completion: nil)
    }
    
    //MARK: 滑动的子控制
    override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
        
        let titleArray = [todayHeadlines,unsecuredLoans,mortgageLoan,consumerLoans,businessLoan,providentFundLoan,smallLoans,mortgageStrategy,carLoanStrategy,hotReading,newGash]
        let urlArray = ["9","10","11","12","13","14","15","16","17","18","20"]
        
        var viewControllers = [UIViewController]()
        
        for i in 0..<titleArray.count {
            let loansNewsVC = LoansNewsViewController.init(urlString: urlArray[i])
            loansNewsVC.delegate = self
            loansNewsVC.itemInfo.title = titleArray[i]
            viewControllers.append(loansNewsVC)
        }
        
        return viewControllers
    }
    

}

extension LoansRootNewsViewController : LoansNewsDelegate {
    
    //MARK: 更新标题
    func updateTitle() {
        self.loansDelegate?.updateTitle!()
    }
    
    //MARK: 改变坐标
    func changeScrollHeight(height: CGFloat) {
        self.loansDelegate?.changeScrollHeight!(height: height)
    }
    
}
